package tianwang.dao;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import tianwang.model.TDModel;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;


public class IBatisDao {
	private SqlMapClient sqlMap = null;
	
	public IBatisDao() throws IOException{
		if(sqlMap == null){
			String resource = "ibatisconfig/config.xml";
			Reader reader = Resources.getResourceAsReader(resource);

			sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
		}
	}
	
	
	public void insert(TDModel model) throws SQLException{
		try {
			sqlMap.startTransaction();
			
			sqlMap.insert("td.insert", model);
			
			sqlMap.commitTransaction();

		} finally {
			sqlMap.endTransaction();
		}
	}
	
	
}
